package com.sl.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 用于返回json数据
 * 
 * @author Heguangchuan
 *
 */
public class MsgHelper {

	private int code;
	private String msg;
	private Map<String, Object> data = new HashMap<>();

	public MsgHelper(int code, String msg) {
		super();
		this.code = code;
		this.msg = msg;
	}

	public MsgHelper() {
		super();

	}

	public MsgHelper put(String key, Object value) {
		data.put(key, value);
		return this;
	}

	/**
	 * 返回失败的信息
	 * 
	 * @return
	 */
	public static MsgHelper failed() {
		return new MsgHelper(0, "failed");
	}

	/**
	 * 返回成功的信息
	 * 
	 * @return
	 */
	public static MsgHelper success() {
		return new MsgHelper(1, "success");
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Map<String, Object> getData() {
		return data;
	}

	public void setData(Map<String, Object> data) {
		this.data = data;
	}

}
